<template>
	<!-- 修改密码 -->
	<view class="warp">
		<!-- #ifdef APP-PLUS -->
		<view class="title-contents"><view class="top-view status"></view></view>
		<!-- #endif -->
		<view class="login-phone form-wapper">

			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-mima2"></text></view>
				<view class="mobile rside"><input placeholder-class="input-placeholder" type="password" placeholder="请输入原密码" v-model="oldpassword"/></view>
			</view>
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-mima2"></text></view>
				<view class="mobile rside"><input placeholder-class="input-placeholder" type="password" placeholder="请输入新密码" v-model="newpasswordo"/></view>
			</view>
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-mima2"></text></view>
				<view class="mobile rside"><input placeholder-class="input-placeholder" type="password" placeholder="请再次输入新密码" v-model="newpasswordt"/></view>
			</view>
		</view>

		<button type="primary" class="login-btn" @click="edit_pwd">修改</button>

	</view>
</template>
<script>
	export default{
		data(){
			return{
				oldpassword:'',
				newpasswordo:'',
				newpasswordt:'',
				uid:'',
				host: 'https://4de16698-d9f4-443a-b416-ef1037cce952.bspapp.com/http'
			}
		},
		methods:{
			edit_pwd(){
				if (this.oldpassword == "") {
					uni.$u.toast('请填写旧密码')
					return false
				}
				if (this.newpasswordo == "") {
					uni.$u.toast('请填写新密码')
					return false
				}
				if (this.newpasswordt == "") {
					uni.$u.toast('请再次填写新密码')
					return false
				}
				if (this.newpasswordo !== this.newpasswordt) {
					uni.$u.toast('两次输入的新密码不一致')
					return false
				}
				let uid=uni.getStorageSync('uid')
				this.uid=uid;
				uni.request({
					method:'POST',
					data:{
						oldPassword:this.oldpassword,
						newPassword:this.newpasswordt,
						uid:this.uid
					},
					url:this.host+'/user/updatePwd',
					success:(res) => {
						console.log(res);
						if(res.data.code==0){
							uni.$u.toast('修改成功，请重新登录')
							uni.clearStorageSync()
							setTimeout(function(){
								uni.navigateTo({
									url:'/pages/public/login'
								})
							},500)
						}else{
							uni.$u.toast(res.data.msg)
						}
					},
					fail: () => {
						console.log('请求失败');
					} 
				})
			}
		}
	}
</script>
<style lang="scss">
@import  "login.scss"
</style>
